package com.neu.flashmall.product.controller;

import com.neu.common.utils.Result;
import com.neu.flashmall.product.entity.PmsSkuImages;
import com.neu.flashmall.product.feign.ThirdPartyFeignService;
import com.neu.flashmall.product.service.PmsSkuImagesService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "/pms_skuImages")
public class PmsSkuImagesController {
    @Resource
    private PmsSkuImagesService pmsSkuImagesService;

    @GetMapping("/getBySkuId")
    public Result getAllBySkuId(Long skuId){
        List<PmsSkuImages> all = pmsSkuImagesService.getAllBySkuId(skuId);
        return Result.ok().put(all);
    }

    @PutMapping("/addImage")
    public Result addImage(@RequestBody PmsSkuImages pmsSkuImages){
        String result = this.pmsSkuImagesService.addImage(pmsSkuImages);
        if("添加成功".equals(result)){
            return Result.ok().setMessage(result);
        }
        return Result.error().setMessage(result);
    }

    @DeleteMapping("/deleteImage")
    public Result deleteImage(Long id){
        String result = this.pmsSkuImagesService.deleteImage(id);
        if("删除成功".equals(result)){
            return Result.ok().setMessage(result);
        }
        return Result.error().setMessage(result);
    }

    @GetMapping("/setDefault")
    public Result setDefault(Long skuId,Long id ){
        String result = this.pmsSkuImagesService.setDefault(skuId, id);
        if("更新成功".equals(result)){
            return Result.ok().setMessage(result);
        }
        return Result.error().setMessage(result);
    }
}
